package org.apache.ocean;

import org.apache.lucene.util.PriorityQueue;
import org.apache.lucene.search.*;
import org.apache.lucene.index.*;
import java.util.*;

/**
 *
 * @author jasonr
 */
public class FieldReaderSortedQueue extends PriorityQueue {
	CSortFields sortFields;
  
  public FieldReaderSortedQueue(CSortFields sortFields, long size) {
    this.sortFields = sortFields;
    initialize((int)size);
  }
  
  protected final boolean lessThan(final Object a, final Object b) {
  	CFieldDoc docA = (CFieldDoc)a;
  	CFieldDoc docB = (CFieldDoc)b;
    final int n = sortFields.size();
		int c = 0;
		for (int i=0; i < n && c==0; ++i) {
      c = docA.fields[i].compareTo(docB.fields[i]);
      if (sortFields.get(i).reverse) {
				c = -c;
			}
    }
    if (c == 0) return docA.doc > docB.doc;
    return c > 0;
  }
}
